
import Vue from 'vue'
// 引入vuex
import Vuex from 'vuex'


// 将vuex全局注入到vue中
Vue.use(Vuex)

export const ADD = 'ADD'

// 创建vuex 实例对象store
const store = new Vuex.Store({
    state: {
        count: 0,
        todos: [
            { id: 1, text: '...', done: true },
            { id: 2, text: '...', done: false }
        ]
    },

    getters:{
      getTodoById:(state)=>(id)=>{
          return state.todos.filter(item => item.id===id);
      },
      getAllTodo:(state) =>{
            return state.todos;
      }
    },

    mutations: {
        [ADD] (state) {
            state.count++
        },
        decrease(state){
            state.count--
        }
    }
})


//对外暴露store对象
export default  store;
